package tech.xs.common.framework.util;

import tech.xs.common.framework.domain.exception.BusinessException;
import tech.xs.common.sys.domain.enums.SysDictValueTypeEnum;

/**
 * 字典工具
 *
 * @author 沈家文
 * @since 2023/5/17$ 13:43$
 */
public class DictUtil {

    public static <T> T getCodeValue(SysDictValueTypeEnum valueType, String code) {
        Object v = null;
        try {
            switch (valueType) {
                case INT: {
                    v = Integer.parseInt(code);
                    break;
                }
                case LONG: {
                    v = Long.parseLong(code);
                    break;
                }
                case STRING:
                default: {
                    v = code;
                    break;
                }
            }
        } catch (Exception e) {
            throw new BusinessException("字典数据类型转换异常 valueType:" + valueType + " code:" + code);
        }
        return (T) v;
    }

}
